#!/usr/bin/env sh

set -ue

SCRIPT_PATH=$(cd $(dirname $0) && pwd)
CMAKE_PATH=$SCRIPT_PATH/..
BUILD_PATH=$SCRIPT_PATH/../build/proj_xcode
THIRD_PARTY_PATH=$CMAKE_PATH/../../thirdParty/

PLATFORM=NONE
NAME=unknown
PS3="Select the platform number to use: "
select var in 'iphoneOS (arm64)' 'iphoneOS Simulator (x86_64)'
do
  case "$var" in
    'iphoneOS (arm64)' ) PLATFORM=OS64; NAME=iphoneos ;;
    'iphoneOS Simulator (x86_64)' ) PLATFORM=SIMULATOR64; NAME=iphonesimulator ;;
    * ) echo "Invalid option $REPLY." ;;
  esac
  break
done

if [ "$PLATFORM" = NONE ]; then
  exit -1
fi

# Run CMake.
cmake -S "$CMAKE_PATH" \
  -B "${BUILD_PATH}_${NAME}" \
  -D CMAKE_TOOLCHAIN_FILE="$THIRD_PARTY_PATH/ios-cmake/ios.toolchain.cmake" \
  -D PLATFORM=$PLATFORM \
  -G Xcode
